<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>


        /*  
         1.手机号脱敏 中间4位数*

         什么意思呢？
         其实就是正则的分组，如果在正则外边使用分组，那么就用$1表示左括号1，$2表示左括号2，$3表示左括号3，
         然后使用replace去替换

         2.手机号格式化

        */

        let phone = '13890665501'

        // 脱敏
      
        let p1 = phone.replace(/(\d{3})(\d{4})(\d{4})/g, "$1****$3")

        //格式化138-9066-5501
      
        let p2 = phone.replace(/(\d{3})(\d{4})(\d{4})/g, "$1-$2-$3")

        console.log(p2);



    </script>

</body>

</html>